package ar.edu.itba.it.raytracer.engine

import scala.Math.sqrt

object Vector {
//  implicit def doubleToVector(that: Double) = Vector(that, that, that)
  val up = Vector(0, 1, 0)
  val down = Vector(0, -1, 0)
  val left = Vector(-1, 0, 0)
  val right = Vector(1, 0, 0)
  val front = Vector(0, 0, 1)
  val behind = Vector(0, 0, -1)
}

case class Vector(val x: Double, val y: Double, val z: Double) {
  def +(that: Vector) = Vector(x + that.x, y + that.y, z + that.z)
  def -(that: Vector) = Vector(x - that.x, y - that.y, z - that.z)
  def *(that: Vector) = x * that.x + y * that.y + z * that.z
  def **(that: Vector) = Vector(y * that.z - z * that.y, z * that.x - x * that.z, x * that.y - y * that.x)
  def *(n: Double) = Vector(x * n, y * n, z * n)
  def /(n: Double) = Vector(x / n, y / n, z / n)
  lazy val norm1 = sqrt(x * x + y * y + z * z)
  lazy val normalized = this / norm1
  override def toString = "(" + x + ", " + y + ", " + z + ")"
}

class RichVector(self: Vector) {
  def *(that: Vector) = Vector(self.x * that.x, self.y * that.y, self.z * that.z)
}

object RichVector {
  implicit def double2RichVector(that: Double) = new RichVector(Vector(that, that, that)) 
}